package org.shopen.puremvc.model.domain.theory
{
	import org.shopen.puremvc.model.domain.ISerializable;
	
	public class Stage implements ISerializable
	{
		[Bindable]
		private var _meta : StageMeta = new StageMeta();
		[Bindable]
		public function get meta() : StageMeta
		{
			return _meta;
		}
		public function set meta(value : StageMeta) : void
		{
			_meta = value;
		}
		
		[Bindable]
		private var _theoryItems : Array = new Array();
		[Bindable]
		public function get theoryItems() : Array
		{
			return _theoryItems;
		}
		public function set theoryItems(value : Array) : void
		{
			_theoryItems = value;
		}
		
		public function Stage(node : XML = null)
		{
			if (node != null)
			{
				deserialize(node);
			}
		}
		
		public function serialize() : XML
		{
			var resultNode : XML = <stage></stage>;
			resultNode = meta.serialize(resultNode);
			for each (var theory : Theory in theoryItems)
			{
				var theoryNode : XML = theory.serialize();
				resultNode.appendChild(theoryNode);
			}
			
			return resultNode;
		}
		
		public function deserialize(node : XML) : void
		{
			meta.deserialize(node);
			
			theoryItems = new Array();
			for each(var theoryNode : XML in node..theory)
			{
				var theoryItem : Theory = new Theory(theoryNode);
				theoryItems.push(theoryItem);
			}
		}
	}
}